import {
	reactive
} from 'vue'
export default function useShare(config = {}) {
	// const userId = uni.getStorageSync('userId')
	// config.path = config.path ? config.path + `?fid=${userId}` : `/pages/index/index?fid=${userId}`

	const state = reactive({
		title: config.title || '新君涛验车',
		path: config.path,
		imageUrl: config.imageUrl || ''
	})

	return {
		state,
		onLoad(options) {
			if (options.scene) {
				const canshu = decodeURIComponent(options.scene)
				if (canshu.indexOf('fid=') > -1) {
					const fid = canshu.substring(canshu.indexOf('fid=') + 4);
					uni.setStorageSync('fid', fid)
				}
			}
			if (options.fid) {
				uni.setStorageSync('fid', options.fid)
			}
		},
		onShareAppMessage() {
			const userId = uni.getStorageSync('userId')
			state.path = state.path ? state.path + `?fid=${userId}` : `/pages/index/index?fid=${userId}`
			return {
				title: state.title,
				path: state.path,
				imageUrl: state.imageUrl || ''
			}
		},
		onShareTimeline() {
			const userId = uni.getStorageSync('userId')
			state.path = state.path ? state.path + `?fid=${userId}` : `/pages/index/index?fid=${userId}`
			return {
				title: state.title,
				path: state.path,
				imageUrl: state.imageUrl || ''
			}
		}
	}
}